package yf.mall.dao;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import yf.mall.entity.KolOrderEntity;
import yf.mall.vo.KolOrderVo;
import org.apache.ibatis.annotations.Mapper;
import com.yf.dao.BaseDao;
import yf.mall.vo.app.product.KolProductSumVo;

import java.util.Date;
import java.util.List;
/**
 * 订单信息表Dao
 *
 *
 *
 * @date Tue Jul 18 14:30:26 CST 2023
 */
@Mapper
public interface KolOrderDao extends BaseDao<KolOrderEntity> {

    List<KolOrderVo> findVo(KolOrderVo vo);

    KolOrderVo getVo(Long id);

    @Select("select *  from kol_order where author_openid = #{authId} and pay_success_time between #{startDate} and #{endDate} and product_id = #{productId} ")
    List<KolOrderEntity> findByAuthIdAndTimeAndProduct(@Param("authId") String authId, @Param("startDate") Date startDate, @Param("endDate") Date endDate, @Param("productId") Long productId);


    @Select("select *  from kol_order where author_openid = #{openId} order by pay_success_time desc limit 1")
    KolOrderEntity findByOpenIdDesc(@Param("openId") String openId);


    @Select(" SELECT product_id as id,count(id) as amount FROM kol_order WHERE product_id in (SELECT id FROM kol_product)  GROUP BY product_id order by amount desc")
    List<KolProductSumVo> sumProduct();

}
